package com.ruoyi.supply.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.supply.enums.SupplyInfoTypeEnum;
import com.ruoyi.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.supply.mapper.SupplyInfoMapper;
import com.ruoyi.supply.domain.SupplyInfo;
import static com.ruoyi.supply.config.Constant.*;

/**
 * 货源 资讯Service业务层处理
 * 
 * @author Ryan
 * @date 2025-06-05
 */
@Service
public class SupplyInfoService extends BaseInfoService<SupplyInfo, SupplyInfoMapper>
{
    @Autowired
    private SupplyInfoMapper supplyInfoMapper;

    @Autowired
    private TInfoImgService tInfoImgService;

    @Autowired
    private TAdminAuditLogService adminAuditLogService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    public SupplyInfoService() {
        super(SupplyInfoTypeEnum.SOURCE);
    }



    @Override
    protected void afterGetId(SupplyInfo supplyInfo){
        Map<String, String> dictMap = getDictMap();
        supplyInfo.setCategoryLabel(dictMap.get(supplyInfo.getCategory()));
    }

    @Override
    protected void afterSelectList(List<SupplyInfo> list) {
        Map<String, String> dictMap = getDictMap();
        list.forEach(it->it.setCategoryLabel(dictMap.get(it.getCategory())));
    }

    private  Map<String, String> getDictMap(){
        List<SysDictData> sysDictData = dictTypeService.selectDictDataByType(DICT_TYPE);
        Map<String, String> dictData = sysDictData.stream()
                .collect(Collectors.toMap(
                        SysDictData::getDictValue,  // key 映射
                        SysDictData::getDictLabel, // value 映射
                        (existing, replacement) -> existing // 处理键冲突的合并函数
                ));
        return dictData;
    }


}
